using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using NBusiness.CodeDom;
using NBusiness.Data.Rules;

namespace NBusiness.Data.Rules.Validation
{
    [Serializable]
    //[ExpectedArgumentType(typeof(RegexEventArgs))]
    public sealed class RegexRule : ValidationRule
    {
        public RegexRule(Type type, string field, RegexEventArgs e)
            : base(type, field, ValidateRegexRule, e, "Resources.RegexRuleMessage")
        { }

        public static bool ValidateRegexRule(object value, ValidationEventArgs e)
        {
            RegexEventArgs arg = e as RegexEventArgs;
            bool retVal = true;
            if (value != null)
            {
                Regex relationship = new Regex(arg.Expression);
                retVal = relationship.IsMatch((string)value);
            }
            return retVal;
        }
    }
}
